package com.smzd.projforge.business;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smzd.core.business.AbstractService;
import com.smzd.core.dao.IDao;
import com.smzd.core.utils.json.FGRowConverter;
import com.smzd.projforge.dao.ProjectDao;
import com.smzd.projforge.domain.Project;
import com.smzd.projforge.domain.Suit;

@Service
public class ProjectService extends AbstractService<Project> {
	@Autowired
	private ProjectDao dao;
	
	@Override
	protected IDao<Project> getDao() {
		return dao;
	}

	@Override
	protected FGRowConverter<Project> getConverter() {
		return ConverterHolder.converter;
	}

	static class ConverterHolder{
		static final FGRowConverter<Project> converter = new FGRowConverter<Project>() {
			@Override
			public Object[] convert(Project elem) {
			    Suit suit = elem.getSuit();
				Object[] fs = new Object[]{
						elem.getId(),
						elem.getName(),
						elem.getPackageName(),
						elem.getDbtype(),
						elem.getDbprefix(),
						elem.getEntry(),
						elem.getDescription(),
						AbstractService.getObjectByField(suit),
						elem.isDisabled(),
				};
				return fs;
			}
		};
	}
}
